package cn.pxs.controller;

import cn.pxs.entity.Order;
import cn.pxs.entity.OrderLine;
import cn.pxs.mapper.OrdMapper;
import cn.pxs.service.OrdService;
import cn.pxs.tool.RespJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/api/adm/ord")
public class AdmOrdController {
    @Autowired
    OrdService ordService;

    @ResponseBody
    @RequestMapping("/addShip")
    //需要传递 JSON格式 的数据
    public Map addShip(@RequestBody Order order){
        if (order.getOrdid()==null || order.getShipno() == null){
            return RespJson.pack(400,"添加快递失败",null);
        }
        ordService.updateShip(order);
        return RespJson.pack(200,"添加快递成功",null);
    }

    @ResponseBody
    @RequestMapping("/findOrdInfo/{start}/{num}")
    //绑定了 start  和 num
    public Map findOrdInfo(@PathVariable("start")Integer start,
                           @PathVariable("num")Integer num,
                           String tstart,String tend,
                           OrderLine orderLine){
        if(start == null || num == null)return RespJson.pack(400,"start,num没值啊..",null);
        Map m1 = new HashMap();
        m1.put("tstart",tstart);
        m1.put("tend",tend);
        Map data = new HashMap();
        data.put("total",ordService.findOrdInfoLine(orderLine,m1));//根据条件查找行数
        data.put("orders",ordService.findOrdInfo(start, num, orderLine,m1));//根据条件查找orderLine对应数据
        return RespJson.pack(200,"查询数据成功",data);
    }

    @ResponseBody
    @RequestMapping("/findItemInfoByOrdid/{ordid}")
    //绑定了地址栏的 ordid
    public Map findItemInfoByOrdid(@PathVariable("ordid")Integer ordid){

       return RespJson.pack(200,"查询成功",ordService.findItemInfoByOrdid(ordid));
    }


}
